package com.yunhe.policyfulfillment.policyful.controller;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.policyfulfillment.policyful.domain.PolicyResult;
import com.yunhe.policyfulfillment.policyful.model.PolicyResultQueryCondition;
import com.yunhe.policyfulfillment.policyful.model.PolicyResultVo;
import com.yunhe.policyfulfillment.policyful.model.PublishStatus;
import com.yunhe.policyfulfillment.policyful.service.PolicyResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description 结果公示表
 * @author misty
 * @date 2021-09-17
 */
@Api(value = "PolicyResult", description = "Model_PolicyResult", tags = {"结果公示表维护"})
@RestController
@RequestMapping(value = "/policyResult")
public class PolicyResultController {

    @Autowired
    private PolicyResultService policyResultService;

    /**
     * 新增
     * @author misty
     * @date 2021/09/17
     **/
    @ApiOperation("新增结果公示表")
    @PostMapping("/createPolicyResult")
    public ResponseEntity<ResultObject> createPolicyResult(@RequestBody PolicyResult policyResult) throws ArgumentErrorException {
        policyResultService.createPolicyResult(policyResult);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 刪除
     * @author misty
     * @date 2021/09/17
     **/
    @ApiOperation("根据id删除结果公示表")
    @DeleteMapping("/deletePolicyResult")
    public ResponseEntity<ResultObject> deletePolicyResult(@RequestParam(value = "id",required = true) int id){
        policyResultService.deletePolicyResult(id);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 新增
     * @author misty
     * @date 2021/09/17
     **/
    @ApiOperation("查询列表")
    @PostMapping("/findPolicyResultByCondition")
    public ResponseEntity<ResultObject<List<PolicyResultVo>>> findPolicyResultByCondition(@RequestBody PolicyResultQueryCondition policyResultQueryCondition) throws ArgumentErrorException {
        PageResult pageResult = policyResultService.findPolicyResultByCondition(policyResultQueryCondition);
        return new ResponseEntity(new ResultObject<>(pageResult), HttpStatus.OK);
    }

    /**
     * 更新
     * @author misty
     * @date 2021/09/17
     **/
    @ApiOperation("更新结果公示表")
    @PostMapping("/updatePolicyResult")
    public ResponseEntity<ResultObject> updatePolicyResult(@RequestBody PolicyResult policyResult){
        policyResultService.updatePolicyResult(policyResult);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     * @author misty
     * @date 2021/09/17
     **/
    @ApiOperation("根据id查询结果公示表")
    @GetMapping("/findPolicyResultById")
    public ResponseEntity<ResultObject<PolicyResult>> findPolicyResultById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(policyResultService.findPolicyResultById(id)),HttpStatus.OK);
    }

    /**
     * 设置发布状态
     * @date 2021/07/23
     **/
    @ApiOperation("设置发布状态")
    @PostMapping("/setPublishStatus")
    public ResponseEntity<ResultObject> setPublishStatus(@RequestBody PublishStatus publishStatus) throws ArgumentErrorException {
        policyResultService.setPublishStatus(publishStatus);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

}